In [1]:
import warnings
warnings.filterwarnings('ignore')
import geopandas as gpd
import pandas as pd
import contextily as ctx
import folium
import matplotlib.pyplot as plt
import matplotlib.colors as colors
import matplotlib.patheffects as pe
from pointpats import centrography
import seaborn as sns
import calendar
import branca.colormap as cm
In [2]:
# Import preprocessed data
folder_path = "data/final_processed_data/"
neighborhood_stats = gpd.read_file(folder_path + "neighborhood_stats.gpkg")
airbnb_gdf = gpd.read_file(folder_path + "airbnb_listings.gpkg")
airbnb_prices = gpd.read_file(folder_path + "airbnb_prices.gpkg")
airbnb_prices_entirespace = gpd.read_file(folder_path + "airbnb_prices_entirespace.gpkg")
airbnb_prices_entirespace_highseason = gpd.read_file(folder_path + "airbnb_prices_entirespace_highseason.gpkg")
airbnb_prices_entirespace_lowseason = gpd.read_file(folder_path + "airbnb_prices_entirespace_lowseason.gpkg")
poi_gdf = gpd.read_file(folder_path + "tourism_pois.gpkg")
museums_gdf = gpd.read_file(folder_path + "museum_pois.gpkg")
galleries_gdf = gpd.read_file(folder_path + "gallery_pois.gpkg")
monuments_gdf = gpd.read_file(folder_path + "monument_pois.gpkg")
buurten_gdf = gpd.read_file(folder_path + "neighborhood_polygons.gpkg")
if neighborhood_stats.crs != "EPSG:28992" or airbnb_gdf.crs != "EPSG:28992" or airbnb_prices.crs != "EPSG:28992" or airbnb_prices_entirespace.crs != "EPSG:28992" or airbnb_prices_entirespace_highseason.crs != "EPSG:28992" or airbnb_prices_entirespace_lowseason.crs != "EPSG:28992" or poi_gdf.crs != "EPSG:28992" or museums_gdf.crs != "EPSG:28992" or galleries_gdf.crs != "EPSG:28992" or monuments_gdf.crs != "EPSG:28992" or buurten_gdf.crs != "EPSG:28992":
print("Convert all datasets to EPSG:28992")
else:
print("All dataset CRS are set to EPSG:28992")
All dataset CRS are set to EPSG:28992
Census neighborhood polygons¶
In [3]:
# Contextily basemaps
# Reproject for contextily
buurten_3857 = buurten_gdf.to_crs(epsg=3857)
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(16, 8))
# Amsterdam map
buurten_3857.plot(ax=ax1,edgecolor="yellow",facecolor="red",alpha=0.2,linewidth=0.5)
ctx.add_basemap(ax1,source=ctx.providers.Esri.WorldImagery,crs=buurten_3857.crs)
ax1.set_title("Amsterdam Census Neighborhoods", fontsize=12)
ax1.set_axis_off()
# Netherlands Map
amsterdam_point = buurten_3857.unary_union.centroid
x_pt, y_pt = amsterdam_point.x, amsterdam_point.y
margin = 750_000
ax2.set_xlim(x_pt - margin, x_pt + margin)
ax2.set_ylim(y_pt - margin, y_pt + margin)
ctx.add_basemap(ax2,source=ctx.providers.CartoDB.Voyager,crs=buurten_3857.crs)
ax2.scatter(x_pt,y_pt,s=150,marker="*",color="red",edgecolor="black",linewidth=1,zorder=5)
ax2.set_title("Amsterdam Location", fontsize=12)
ax2.set_axis_off()
plt.tight_layout()
plt.show()
Nationally Registered Monuments¶
In [4]:
# Joint Plot Map
monuments_gdf_3857 = monuments_gdf.to_crs(epsg=3857)
monuments_gdf_3857["longitude"] = monuments_gdf_3857.geometry.x
monuments_gdf_3857["latitude"] = monuments_gdf_3857.geometry.y
mean_center = centrography.mean_center(monuments_gdf_3857[["longitude", "latitude"]])
med_center = centrography.euclidean_median(monuments_gdf_3857[["longitude", "latitude"]])
# Generate scatterplot
joint_axes = sns.jointplot(x="longitude", y="latitude", data=monuments_gdf_3857, s=0.75, height=9)
# Add mean point and marginal lines
joint_axes.ax_joint.scatter(*mean_center, color="red", marker="x", s=50, label="Mean Center")
joint_axes.ax_marg_x.axvline(mean_center[0], color="red")
joint_axes.ax_marg_y.axhline(mean_center[1], color="red")
# Add median point and marginal lines
joint_axes.ax_joint.scatter(*med_center,color="limegreen",marker="o",s=50,label="Median Center")
joint_axes.ax_marg_x.axvline(med_center[0], color="limegreen")
joint_axes.ax_marg_y.axhline(med_center[1], color="limegreen")
# Legend
joint_axes.ax_joint.legend()
# Add basemap
ctx.add_basemap(joint_axes.ax_joint, source=ctx.providers.CartoDB.Positron)
# Clean axes
joint_axes.ax_joint.set_axis_off()
# Display
plt.show()
In [5]:
# Hexbin map
# Set up figure and axis
f, ax = plt.subplots(1, figsize=(12, 9))
hb = ax.hexbin(monuments_gdf_3857["longitude"],monuments_gdf_3857["latitude"],gridsize=50,linewidths=0,alpha=0.5,cmap="viridis_r",)
# Add basemap
ctx.add_basemap(ax, source=ctx.providers.CartoDB.Positron)
# Add colorbar
plt.colorbar(hb)
# Remove axes
ax.set_axis_off()
In [6]:
# Leaflet interactive map
monuments_wgs = monuments_gdf.to_crs(epsg=4326).copy()
center = [monuments_wgs.geometry.y.mean(),monuments_wgs.geometry.x.mean()]
interactive_monuments_map = folium.Map(location=center, zoom_start=12, tiles="CartoDB positron")
for _, row in monuments_wgs.iterrows():
geom = row.geometry
if geom is None:
continue
lat = geom.y
lon = geom.x
herkomst = row.get("herkomst", "NA")
subcategor = row.get("subcategor", "NA")
tooltip_text = f"Origin: {herkomst}<br>Subcategory: {subcategor}"
folium.CircleMarker(location=[lat, lon],radius=1.5,color="orange",fill=True,fill_color="orange",popup=tooltip_text,tooltip=tooltip_text).add_to(interactive_monuments_map)
interactive_monuments_map
Out[6]:
Make this Notebook Trusted to load map: File -> Trust Notebook